package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.ElectronicFence;
import com.ruoyi.system.service.IElectronicFenceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * fenceController
 * 
 * @author ruoyi
 * @date 2023-09-25
 */
@RestController
@RequestMapping("/fence")
public class ElectronicFenceController extends BaseController
{
    @Autowired
    private IElectronicFenceService electronicFenceService;

    /**
     * 查询fence列表
     */
    @RequiresPermissions("system:fence:list")
    @GetMapping("/list")
    public TableDataInfo list(ElectronicFence electronicFence)
    {
        startPage();
        List<ElectronicFence> list = electronicFenceService.selectElectronicFenceList(electronicFence);
        return getDataTable(list);
    }




/**
     * 导出fence列表
     */
    @RequiresPermissions("system:fence:export")
    @Log(title = "fence", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, ElectronicFence electronicFence)
    {
        List<ElectronicFence> list = electronicFenceService.selectElectronicFenceList(electronicFence);
        ExcelUtil<ElectronicFence> util = new ExcelUtil<ElectronicFence>(ElectronicFence.class);
        util.exportExcel(response, list, "fence数据");
    }






    /**
     * 获取fence详细信息
     */
    @GetMapping(value = "/{electronicId}")
    public AjaxResult getInfo(@PathVariable("electronicId") Long electronicId)
    {
        return success(electronicFenceService.selectElectronicFenceByElectronicId(electronicId));
    }




    /**
     * 新增fence
     */
    @RequiresPermissions("system:fence:add")
    @Log(title = "fence", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElectronicFence electronicFence)
    {
        return toAjax(electronicFenceService.insertElectronicFence(electronicFence));
    }


    /**
     * 修改fence
     */
    @RequiresPermissions("system:fence:edit")
    @Log(title = "fence", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElectronicFence electronicFence)
    {
        return toAjax(electronicFenceService.updateElectronicFence(electronicFence));
    }

    /**
     * 删除fence
     */
    @RequiresPermissions("system:fence:remove")
    @Log(title = "fence", businessType = BusinessType.DELETE)
	@DeleteMapping("/{electronicIds}")
    public AjaxResult remove(@PathVariable Long[] electronicIds)
    {
        return toAjax(electronicFenceService.deleteElectronicFenceByElectronicIds(electronicIds));
    }
}
